package com.weather.wangs.weather.weather;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.weather.wangs.weather.R;

/**
 * Created by wangs on 2015/11/10.
 */
public class WeatherActivity extends Activity implements View.OnClickListener, WeatherOnFinishedListener {

    private WeatherModel weatherModel;
    private Dialog loadingDialog;
    private TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_weather_main);
        weatherModel = new WeatherModelImpl();
        initView();
    }

    /**
     * 初始化View
     */
    private void initView() {
        textView = (TextView) findViewById(R.id.textView);
        textView.setOnClickListener(this);
        textView.setText("点我查看天气");
        loadingDialog = new ProgressDialog(this);
        loadingDialog.setTitle("加载天气中...");
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.textView:
                loadingDialog.show();
                String url = "http://www.weather.com.cn/data/sk/101010100.html";
                weatherModel.getWeather(WeatherActivity.this, url, this);
                break;
        }
    }

    @Override
    public void onSuccess(String tag, String string) {
        loadingDialog.dismiss();
        textView.setText(string);
//        WeatherBean weather = UtilGson.httpFormat(string, WeatherBean.class);
    }

    @Override
    public void onFailure(String tag, int errorNo, String strMsg) {
        loadingDialog.dismiss();
    }

    @Override
    public void onError(String tag, String error) {
        loadingDialog.dismiss();
    }
}
